package com.cn.ysf.newbeemall.controller.mall;

import com.cn.ysf.newbeemall.controller.vo.NewBeeMallGoodsDetailvo;
import com.cn.ysf.newbeemall.pojo.TbNewbeeMallGoodsInfo;
import com.cn.ysf.newbeemall.service.NewBeeMallGoodsService;
import com.cn.ysf.newbeemall.util.BeanUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author ysf
 * @date 2019/12/10 15:40
 */
@Controller
public class GoodsController {

    @Resource
    private NewBeeMallGoodsService newBeeMallGoodsService;

    /**
     * 前台接收商品id进行处理
     * @param goodsId
     * @param request
     * @return
     */
    @RequestMapping("/goods/detail/{goodsId}")
    public String detailPage(@PathVariable("goodsId") Long goodsId, HttpServletRequest request){
        if(goodsId<1){
            return "error/error_5xx";
        }
        TbNewbeeMallGoodsInfo tbNewbeeMallGoodsInfo=newBeeMallGoodsService.selectByPrimaryKey(goodsId);
        if(tbNewbeeMallGoodsInfo==null){
            return "error/error_404";
        }
        NewBeeMallGoodsDetailvo newBeeMallGoodsDetailvo=new NewBeeMallGoodsDetailvo();
        BeanUtil.copyProperties(tbNewbeeMallGoodsInfo,newBeeMallGoodsDetailvo);
        newBeeMallGoodsDetailvo.setGoodscarouseList(tbNewbeeMallGoodsInfo.getGoodsCarousel().split(","));
        request.setAttribute("goodsDetail",newBeeMallGoodsDetailvo);
        return "mall/detail";
    }


    /**
     * 根据前台查询条件查询商品的信息
     * @param params
     * @param request
     * @return
     */
    @RequestMapping({"/search","/search.html"})
    public String searchPage(@RequestParam Map<String,Object> params,HttpServletRequest request){




        return "";
    }




}
